package router

import (
	"dog-blog/app/template/apis/html"
	"dog-blog/sdk"
	"net/http"

	"github.com/gin-gonic/gin"
)

func InitRouter() {

	router := sdk.Runtime.GetEngine().(*gin.Engine)
	router.Use(gin.Recovery())

	router.NoRoute(noResponse)

	router.SetFuncMap(GetFuncMap())
	router.Static("/static", "./static")
	router.LoadHTMLGlob("view/**/**/*")

	initBlogRouter(router)
}

func noResponse(c *gin.Context) {
	c.HTML(http.StatusOK, "blog/404.html", gin.H{})
}

func initBlogRouter(c *gin.Engine) {
	c.GET("/", html.HTMLIndex)
	c.GET("/article/:id", html.HTMLArticle)
	c.GET("/other", html.HTMLList)
	c.GET("/about", html.HTMLAbout)
	c.GET("/search", html.Search)

	c.GET("develop/game", html.HTMLList)
	c.GET("develop/web", html.HTMLList)
}
